package com.shuai.orderfood.merchants.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shuai.orderfood.merchants.dto.SystemSettingsDto;
import com.shuai.orderfood.merchants.mapper.SystemSettingsMapper;
import com.shuai.orderfood.merchants.pojo.SystemSettings;
import com.shuai.orderfood.merchants.service.SystemSettingsService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.UUID;

/**
 * 系统参数设置
 */

@Service
public class SystemSettingsServiceImpl extends ServiceImpl<SystemSettingsMapper, SystemSettings> implements SystemSettingsService {

    @Resource
    private SystemSettingsMapper systemSettingsMapper;
    @Override
    public boolean saveSystemSetting(SystemSettingsDto systemSettingsDto) throws Exception {
        String paramKey = systemSettingsDto.getParamKey();
        String paramValue = systemSettingsDto.getParamValue();
        String createPeople = systemSettingsDto.getCreatePeople();
        String description = systemSettingsDto.getDescription();
        if(StringUtils.hasLength(paramKey) && StringUtils.hasLength(paramValue)) {
            SystemSettings systemSettings = new SystemSettings();
            String merchantId = UUID.randomUUID().toString();
            systemSettings.setParamKey(paramKey);
            systemSettings.setParamValue(paramValue);
            systemSettings.setMerchantId(merchantId);
            systemSettings.setCreatePeople(createPeople);
            systemSettings.setDescription(description);
            systemSettings.setUpdatePeople(createPeople);
            systemSettingsMapper.insert(systemSettings);
            return true;
        }else {
            return false;
        }
    }
}
